package MysqlUtils;


import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class MysqlMain {
	public static void main(String args[]) throws SQLException {
		MysqlDataSource source = new MysqlDataSource();
		source.setDatabaseName("test");
		source.setURL("jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF8");
		source.setUser("root");
		source.setPassword("123");
		QueryRunner runner = new QueryRunner(source);
		ResultSetHandler handler = new BeanListHandler(Users.class);
		List<Users> ob = (List<Users>) runner.query("select * from users", handler);
		for (Users users : ob)
			System.out.println("id:" + users.getIdusers() + "-name:" + users.getUsername() + "-age" + users.getUserage());
	}
}
